home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / gentype / gentypes.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  8.1 KB  |  281 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "&Proceed"
  4.    ClientHeight    =   2835
  5.    ClientLeft      =   1500
  6.    ClientTop       =   1365
  7.    ClientWidth     =   7365
  8.    Height          =   3240
  9.    Left            =   1440
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   2835
  12.    ScaleWidth      =   7365
  13.    Top             =   1020
  14.    Width           =   7485
  15.    Begin Data Data1 
  16.       Caption         =   "Data1"
  17.       Connect         =   ""
  18.       DatabaseName    =   ""
  19.       Exclusive       =   0   'False
  20.       Height          =   270
  21.       Left            =   120
  22.       Options         =   0
  23.       ReadOnly        =   -1  'True
  24.       RecordSource    =   ""
  25.       Top             =   2460
  26.       Visible         =   0   'False
  27.       Width           =   1155
  28.    End
  29.    Begin CheckBox prtrep 
  30.       Caption         =   "Generate report <Databasename>.LST"
  31.       Height          =   435
  32.       Left            =   1560
  33.       TabIndex        =   6
  34.       Top             =   1020
  35.       Value           =   1  'Checked
  36.       Width           =   5415
  37.    End
  38.    Begin TextBox tabname 
  39.       BackColor       =   &H00C0C0C0&
  40.       Enabled         =   0   'False
  41.       Height          =   315
  42.       Left            =   1920
  43.       TabIndex        =   5
  44.       Text            =   "Working On Table:"
  45.       Top             =   2340
  46.       Width           =   3555
  47.    End
  48.    Begin CheckBox GenTypes 
  49.       Caption         =   "Output VB 3.0 TYPE statements to GENTYPES.LST"
  50.       Height          =   435
  51.       Left            =   1560
  52.       TabIndex        =   4
  53.       Top             =   600
  54.       Value           =   1  'Checked
  55.       Width           =   5415
  56.    End
  57.    Begin CommandButton Command2 
  58.       Caption         =   "&Quit"
  59.       Height          =   495
  60.       Left            =   4080
  61.       TabIndex        =   3
  62.       Top             =   1740
  63.       Width           =   2235
  64.    End
  65.    Begin CommandButton Prt 
  66.       Caption         =   "&Proceed"
  67.       Height          =   495
  68.       Left            =   1020
  69.       TabIndex        =   2
  70.       Top             =   1740
  71.       Width           =   2235
  72.    End
  73.    Begin TextBox Text1 
  74.       Height          =   315
  75.       Left            =   3180
  76.       TabIndex        =   0
  77.       Top             =   180
  78.       Width           =   2415
  79.    End
  80.    Begin Label Label1 
  81.       AutoSize        =   -1  'True
  82.       Caption         =   "Data Base to print:"
  83.       Height          =   195
  84.       Left            =   1500
  85.       TabIndex        =   1
  86.       Top             =   240
  87.       Width           =   1620
  88.    End
  89. Option Explicit
  90. Sub Command2_Click ()
  91. End Sub
  92. Sub Form_Load ()
  93.     Form1.Top = (screen.Height - Form1.Height) / 2
  94.     Form1.Left = (screen.Width - Form1.Width) / 2
  95. End Sub
  96. Sub prt_Click ()
  97. Dim rp$
  98. Dim db As Database
  99. Dim tnames As snapshot
  100. Dim td As Table
  101. Dim fld As Fields
  102. Dim idx As Index
  103. Dim idxcnt As Integer
  104. Dim aq$
  105. Dim i
  106. Dim j
  107. Dim x$
  108. Dim aa$
  109. Dim qq
  110. Dim dset As DynaSet
  111.     'on error GoTo ETrap
  112.     aq$ = text1.Text
  113.     If Len(aq$) = 0 Then
  114.     MsgBox "Please enter a data base name..."
  115.     text1.SetFocus
  116.     Exit Sub
  117.     End If
  118.     x$ = Dir$(aq$)
  119.     If Len(x$) = 0 Then
  120.     MsgBox "Database : " + x$ + " not found on disk..."
  121.     text1.SetFocus
  122.     Exit Sub
  123.     End If
  124.     prt.Enabled = False
  125.     If prtrep.Value = 1 Then
  126.     i = InStr(1, UCase(aq$), ".MDB")
  127.     rp$ = Mid$(aq$, 1, i) + "LST"
  128.     Open rp$ For Output As #22
  129.     End If
  130.     Set db = OpenDatabase(aq$)
  131.     Data1.DatabaseName = db.Name
  132.     Set tnames = db.ListTables() ' Copy Table info to td("
  133.     If GenTypes.Value = 1 Then
  134.     Open "gentypes.lst" For Output As #2
  135.     Print #2, "'Structures from data base: "; aq$; "as of: "; Date$; ", "; Time$
  136.     Print #2, ""
  137.     End If
  138.     If prtrep.Value = 1 Then
  139.     Print #22, "Listing of data base: "; aq$, "Date: "; Date$, "Time: "; Time$
  140.     Print #22,
  141.     Print #22, "Source of data: "; db.Name
  142.     Print #22, "Connect string: "; db.Connect
  143.     Print #22, "Transactions supported? "; db.Transactions
  144.     Print #22, "Sort Order: "; db.CollatingOrder
  145.     Print #22, "Updateable? "; db.Updatable
  146.     Print #22, "Query time-out (secs): "; db.QueryTimeout
  147.     Print #22,
  148.     Print #22, "Number of tables: "; Str$(db.TableDefs.Count)
  149.     Print #22,
  150.     End If
  151.     Do While Not tnames.EOF
  152.     If (tnames("Attributes") And DB_SYSTEMOBJECT) <> 0 Then
  153.         GoTo SkipTd
  154.     End If
  155.     aa$ = tnames("Name")
  156.     Data1.DatabaseName = db.Name
  157.     Data1.RecordSource = aa$
  158.     'On Error Resume Next
  159.     'Data1.recordset.QueryTimeout = 1
  160.     'qq = 1
  161.     Data1.Refresh
  162.     'qq = 1
  163.     'On Error GoTo ETrap
  164.     If prtrep.Value = 1 Then
  165.         Print #22, String$(132, "=")
  166.         Print #22, "Table Name:      "; Data1.Recordset.Name
  167.         Print #22, "Updateable?:     "; Data1.Recordset.Updatable
  168.         Print #22, "Date Created:    "; tnames("DateCreated")
  169.         Print #22, "Last Updated:    "; tnames("LastUpdated")
  170.         Print #22, "Table Type:      ";
  171.         
  172.         
  173.         If (tnames("TableType") And DB_QUERYDEF) = DB_QUERYDEF Then
  174.          Print #22, "QUERYDEF"
  175.         Else
  176.         If (tnames("TableType") And DB_TABLE) = DB_TABLE Then
  177.             Print #22, "TABLE"
  178.             Set td = db.OpenTable(tnames("Name"))
  179.             idxcnt = td.Indexes.Count
  180.             Print #22, "Index count: "; Str$(idxcnt)
  181.             If idxcnt <> 0 Then
  182.                 For i = 0 To idxcnt - 1
  183.                 Set idx = td.Indexes(i)
  184.                 Print #22, "Index name: "; idx.Name
  185.                 Print #22, "    fields: "; idx.Fields
  186.                 Print #22, "   primary: ";
  187.                 If (idx.Primary) Then Print #22, "Yes" Else Print #22, "No"
  188.                 Print #22, "    unique: ";
  189.                 If (idx.Unique) Then Print #22, "Yes" Else Print #22, "No"
  190.                 Print #22, ""
  191.                 Next i
  192.             End If
  193.         Else
  194.             Print #22, "UNKNOWN"
  195.         End If
  196.         End If
  197.         Print #22,
  198.         Print #22, "Record Count:    "; tnames("RecordCount")
  199.         Print #22, "Attributes:      "; Hex$(tnames("Attributes"))
  200.         Print #22, "Fields:"
  201.         Print #22, String$(132, "_")
  202.         Print #22, "Name";
  203.         Print #22, Tab(30); "Type";
  204.         Print #22, Tab(45); "Size";
  205.         Print #22, Tab(50); "Attr";
  206.         Print #22, Tab(55); "C.O.";
  207.         Print #22, Tab(65); "OPos";
  208.         Print #22, Tab(70); "Source Field";
  209.         Print #22, Tab(90); "Source Table";
  210.         Print #22,
  211.         Print #22,
  212.     End If
  213.     If GenTypes.Value = 1 Then
  214.         Print #2, "'"; String$(80, "_")
  215.         Print #2, "Type td_" + tnames("Name")
  216.     End If
  217.     tabname.Text = "Working on table: " + tnames("Name")
  218.     For j = 0 To Data1.Recordset.Fields.Count - 1
  219.         aq$ = ""
  220.         Select Case Data1.Recordset.Fields(j).Type
  221.         Case Is = 1, 2, 3
  222.         aq$ = "Integer"
  223.         Case Is = 4
  224.         aq$ = "Long"
  225.         Case Is = 5
  226.         aq$ = "Currency"
  227.         Case Is = 6
  228.         aq$ = "Single"
  229.         Case Is = 7, 8
  230.         aq$ = "Double"
  231.         Case Is = 9, 10
  232.         aq$ = "String * " + Str$(Data1.Recordset.Fields(j).Size)
  233.         Case Is = 11, 12
  234.         aq$ = "Long"
  235.         Case Else
  236.         aq$ = "UNKNOWN:" + Str$(Data1.Recordset.Fields(j).Type)
  237.         End Select
  238.         If GenTypes.Value = 1 Then
  239.         Print #2, "        "; Data1.Recordset.Fields(j).Name; " AS ";
  240.         Print #2, aq$
  241.         End If
  242.         If Mid$(aq$, 1, 6) = "String" Then
  243.         aq$ = "String"
  244.         End If
  245.         If prtrep.Value = 1 Then
  246.         Print #22, Data1.Recordset.Fields(j).Name;
  247.         Print #22, Tab(30); aq$;
  248.         Print #22, Tab(45); Data1.Recordset.Fields(j).Size;
  249.         Print #22, Tab(50); Hex$(Data1.Recordset.Fields(j).Attributes);
  250.         Print #22, Tab(55); Str$(Data1.Recordset.Fields(j).CollatingOrder);
  251.         Print #22, Tab(65); Str$(Data1.Recordset.Fields(j).OrdinalPosition);
  252.         Print #22, Tab(70); Data1.Recordset.Fields(j).SourceField;
  253.         Print #22, Tab(90); Data1.Recordset.Fields(j).SourceTable
  254.         End If
  255.     Next j
  256.     If prtrep.Value = 1 Then
  257.         Print #22,
  258.         Print #22,
  259.     End If
  260.     If GenTypes.Value = 1 Then
  261.         Print #2, "END TYPE"
  262.     End If
  263. SkipTd:
  264.     'data1.Close
  265.     tnames.MoveNext    ' Move to next record.
  266.     Loop
  267.     If prtrep.Value = 1 Then
  268.     Print #22, "*** END OF REPORT ***"
  269.     printer.EndDoc
  270.     End If
  271.     Beep
  272.     Beep
  273.     MsgBox "Printing completed!"
  274.     End
  275. ETrap:
  276.     aq$ = "An error occurred! " + Chr$(13) + Chr$(10)
  277.     aq$ = aq$ + "Code was: " + Str$(Err) + " " + Error$(Err)
  278.     MsgBox aq$
  279.     End
  280. End Sub
  281.